<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>No.2商城-会员列表</title>
    <link href="../assets/css/bootstrap.min.css" rel="stylesheet">
    <script src="../assets/js/jquery.min.js"></script>
    <script src="../assets/js/bootstrap.min.js"></script>

</head>
<body>
<div class="row" style="width: 100%;">
    <div class="col-md-12">
        <div class="panel panel-default">
            <div class="panel-heading">会员列表</div>
            <div class="panel-body">
                <!-- 条件查询 -->
                <div class="row">
                    <div class="col-xs-6 col-sm-6 col-md-6 col-lg-6">
                        <div class="form-group form-inline">
                            <span>用户名</span>
                            <input type="text" name="username" class="form-control">
                        </div>
                    </div>
                    <div class="col-xs-3 col-sm-3 col-md-3 col-lg-3">
                        <button type="button" class="btn btn-primary" id="search"><span
                                    class="glyphicon glyphicon-search"></span></button>
                    </div>
                </div>
                <!-- 列表显示 -->
                <div style="height: 400px;overflow: scroll;">
                    <table id="tb_list" class="table table-striped table-hover table-bordered">
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    function ondelete(id) {
        $.ajax({
            url: "http://localhost:80/phalapi/public/index.php?s=App.User.delUserById&userId=" + id,
            type: "GET",
            dataType: "JSON",
            success: function (result) {
                var data1 = result.data.row;
            },
            error: function (msg) {
                alert("错误信息：" + msg);
            }
        })
        $.ajax({
            url: "http://localhost:80/phalapi/public/index.php?s=App.Cart.delCartById&userId=" + id,
            type: "GET",
            dataType: "JSON",
            success: function (result) {
                var data2 = result.data.row;
            },
            error: function (msg) {
                alert("错误信息：" + msg);
            }
        })
        window.location.replace("userList.php")
    }

    //显示用户信息
    $(function () {
        $.ajax({
            url: "http://localhost:80/phalapi/public/index.php?s=App.User.getUserList",
            type: "GET",
            dataType: "JSON",
            success: function (result) {
                var user_data = result.data.info;
                var z = 1;
                console.log("data:" + user_data[0]['id'])
                // <li><a href='goods/goodsList.php'></a></li>
                var s = "<tr class='tr_head'><td>编号</td><td>邮箱</td><td>姓名</td><td>性别</td><td>类别</td><td>操作</td></tr>";
                for (var i = 0; i < user_data.length; i++) {
                    var id = user_data[i]['id'];
                    var a = user_data[i]['email'];
                    var b = user_data[i]['username'];
                    var c = user_data[i]['gender'];
                    var d = user_data[i]['role'];
                    if (d == 0) {
                        e = '管理员'
                    } else {
                        e = '会员'
                    }
                    // console.log('price_url=' + price_url)
                    s += "<tr><td>" + (z++) + "</td><td>" + a + "</td><td>" + b + "</td><td>" + c + "</td><td>" + d + "</td><td><button class='btn btn-primary' onclick='ondelete(" + id + ")'>删除</button></td></tr>";
                }
                $("#tb_list").html(s);
            },
            error: function (msg) {
                alert("错误信息：" + msg);
            }
        })
    })


</script>
</body>
</html>